<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/11/22
  Time: 9:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="${pageContext.request.contextPath}/css/Style1.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css"/>
    <script src="${pageContext.request.contextPath}/bootstrap/js/jquery-2.1.0.js"></script>
    <script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.js"></script>
    <title>Title</title>
    <style type="text/css">
        #biaoti{
            height: 24px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
    </style>
</head>
<body>
<div style="background-color:#f5fafe ;width: 100%;height: 100%">
    <div class="row">
        <c:forEach var="c" items="${page.pageList}">
            <div class="col-xs-2"><%--大小--%>
                <div class="thumbnail">
                    <img src="${pageContext.request.contextPath}/${c.image}" alt="" style="height: 20%">
                    <div class="caption">
                        <h5 id="biaoti">${c.pname}</h5>
                        <p>市场价：${c["market_price"]}</p>
                        <p>
                            是否热门：
                          <c:if test="${c[\"is_hot\"] eq 1}">是</c:if>
                            <c:if test="${c[\"is_hot\"] ne 1}">否</c:if>
                        </p>
                        <p><a href="${pageContext.request.contextPath}/AdminProductEditUI" class="btn btn-primary btn-sm" role="button">修改</a> <a href="#" class="btn btn-default btn-sm" role="button">删除</a></p>
                    </div>
                </div>
            </div>
        </c:forEach>

    </div>
    <hr>
    <%--
    规则是：前5 后4  加当前页 一共显示10页
          当前页：page
          开始  ：begin
          结束  ：end
          if(总页数 <=10){
           begin=1;
           end=总页数;
          }else{//页数超过10页   假如当前选择了地4页   共20页

          begin=page-5;        可是4-5=-1
          end=page+4;                           可是20+4=24，不对
          //所以...当begin<1
          if(begin<1){
            begin=1;
            end=10;

          }
          //所以...当end>总页数
          if(end>总页数){
            end=总页数
            begin=总页数-9；


          }


          }

    --%>

    <c:choose>
        <c:when test="${page.pageCount<=10}">
            <c:set var="begin" value="1"/>
            <c:set var="end" value="${page.pageCount}"/>
        </c:when>
        <c:otherwise>
            <c:set var="begin" value="${page.page-5}"/>
            <c:set var="end" value="${page.page+4}"/>

            <c:if test="${begin<1}">
                <c:set var="begin" value="1"/>
                <c:set var="end" value="10"/>
            </c:if>
            <c:if test="${end>page.pageCount}">
                <c:set var="begin" value="${page.pageCount-9}"/>
                <c:set var="end" value="${page.pageCount}"/>
            </c:if>
        </c:otherwise>


    </c:choose>

    <nav aria-label="...">
        <ul class="pagination">
            <c:if test="${page.page ne 1}">
                <li><a href="${pageContext.request.contextPath}/AdminProductFindAll?page=${page.page-1}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
            </c:if>
            <c:forEach var="num" begin="${begin}" end="${end}">
                <c:choose>
                    <c:when test="${page.page eq num}">

                        <li class="active"><span>${num}<span class="sr-only"></span></span></li>
                    </c:when>

                    <c:otherwise>

                        <li ><a href="${pageContext.request.contextPath}/AdminProductFindAll?page=${num}">${num}<span class="sr-only"></span></a></li>
                    </c:otherwise>
                </c:choose>
            </c:forEach>

            <c:if test="${page.page ne page.pageCount}">
                <li ><a href="${pageContext.request.contextPath}/AdminProductFindAll?page=${page.page+1}" aria-label="Previous"><span aria-hidden="true">&raquo;</span></a></li>
            </c:if>

        </ul>
    </nav>

</div>
</body>
</html>
